/************************************************************************/
/*    Author: Scott Bevin                                               */
/************************************************************************/


#pragma once

#include <map>
#include <CEGUI\CEGUI.h>
#include <string>

#include "..\SystemComponent.h"
#include "CEGuiDebugVariableTrackerWindow.h"
#include "..\XCEGui\CEGUIComponent.h"
#include "CEGuiDebuggerTool.h"
#include "../../XMessaging\Messenger.h"

namespace XF
{
	class CEGuiDebuggingTools :
		public SystemComponent,
		public Messenger
	{
	private:
		CEGUIComponent* mGui;
		CEGUI::FrameWindow *mWindow;
		CEGUI::Window* mDebugRoot;

		std::string mSkinFile;
		const float mButtonWidth, mButtonHeight, mSpacing;

		typedef std::map<std::string, std::pair<CEGUI::ButtonBase*, CEGuiDebuggerTool*> > ToolsMap;
		typedef std::map<std::string, std::pair<CEGUI::ButtonBase*, CEGuiDebuggerTool*> >::iterator ToolsMapIt;
		ToolsMap mTools;

		void CreateDebugWindow();
		void RejigPositioning();

		bool ButtonClicked( const CEGUI::EventArgs &args );
		bool TitlebarDoubleClicked( const CEGUI::EventArgs &args );

	public:
		CEGuiDebuggingTools(Application* ownerApp, std::string skinFile);
		~CEGuiDebuggingTools();

		bool OnInitialise();
		void OnShutDown();
		bool OnHandleMessage(const Message &message);
		void OnHandleInput(double dT, Input *input);

		void RegisterTool(std::string name, std::string buttonText, CEGuiDebuggerTool* tool);
		void DestroyTool(std::string name);
	};
}
